﻿/*
* (c) by Andreas Kreisl
*
* Sys Monitor - Plugin: seperator
* Version: 0.1
*
* License: creative commons BY-NC-SA
*/


// --------------------------------------------------------------------------------
// myPlugin Variables (required!)

myPlugins["spacer"] = new Object();
myPlugins["spacer"]["name"] = getLocalizedString2("mod_sysm_plugin_spacer_name");
myPlugins["spacer"]["onlyonce"] = false;
myPlugins["spacer"]["newObject"] = function (NewSettings) { return new plugin_spacer_sensor(NewSettings); }

// --------------------------------------------------------------------------------
// The Sensore Object

function plugin_spacer_sensor(NewSettings) {
	// Required variables
	this.plugin = "spacer";
	this.settings = NewSettings;
	this.edit = plugin_spacer_edit;
	this.ReDraw = plugin_spacer_ReDraw;
	this.frame = new Frame();
	this.frame.window = main;
	this.frame.width = mod_sysmonitor_width;


	// Init Settings
	if(!this.settings.size) this.settings.size = 5;
	if(!this.settings.opacity) this.settings.opacity = 33;


	//The Sonsore
	this.image = new Image();
	this.image.src = "Resources/Black.png";
	this.image.width = this.frame.width;
	this.image.height = this.settings.size;
	this.image.opacity = this.settings.opacity;
	this.frame.appendChild(this.image);


	// Calculating sensore height
	this.frame.height = this.image.height;
	return true;

// --------------------------------------------------------------------------------
// Helper Functions

	function plugin_spacer_edit() {
		var Drive_Edit_DialogFields = Array();
		var FieldID = -1;

		Drive_Edit_DialogFields[++FieldID] = new FormField();
		Drive_Edit_DialogFields[FieldID].title = getLocalizedString2("mod_sysm_plugin_spacer_pref_pixel");
		Drive_Edit_DialogFields[FieldID].type = 'slider';
		Drive_Edit_DialogFields[FieldID].minLength = 3;
		Drive_Edit_DialogFields[FieldID].maxLength = 10;
		Drive_Edit_DialogFields[FieldID].ticks = 8;
		Drive_Edit_DialogFields[FieldID].tickLabel = new Array("3","4","5","6","7","8","9","10");
		Drive_Edit_DialogFields[FieldID].defaultValue = this.settings.size;

		Drive_Edit_DialogFields[++FieldID] = new FormField();
		Drive_Edit_DialogFields[FieldID].title = getLocalizedString2("mod_sysm_plugin_spacer_pref_opacity");
		Drive_Edit_DialogFields[FieldID].type = 'slider';
		Drive_Edit_DialogFields[FieldID].minLength = 0;
		Drive_Edit_DialogFields[FieldID].maxLength = 255;
		//Drive_Edit_DialogFields[FieldID].ticks = 256; // Looks ugly
		Drive_Edit_DialogFields[FieldID].tickLabel = new Array("0%","25%","50%","75%","100%");
		Drive_Edit_DialogFields[FieldID].defaultValue = this.settings.opacity;

		var Drive_Edit_DialogResults = form(Drive_Edit_DialogFields, getLocalizedString2("mod_sysm_plugin_preftitle") + myPlugins[this.plugin]["name"]);
		if (Drive_Edit_DialogResults != null) {
			if ( this.settings.size != Drive_Edit_DialogResults[0] ) {
				this.settings.size = Drive_Edit_DialogResults[0];
				this.image.height = this.settings.size;
				this.frame.height = this.image.height;
				mod_sysmonitor_ReDraw();
			}
			if ( this.settings.opacity != Drive_Edit_DialogResults[1] ) {
				this.settings.opacity = Drive_Edit_DialogResults[1];
				this.image.opacity = this.settings.opacity;
			}
		} else {
			//print("form was cancelled");
		}
		delete Drive_Edit_DialogFields;
		return true;
	}

	function plugin_spacer_ReDraw() {
		this.frame.width = mod_sysmonitor_width;
		this.image.width = this.frame.width;
		return true;
	}

}

// --------------------------------------------------------------------------------
// The END